package com.acme.bankapp.domain.bank;

import com.acme.bankapp.service.bank.ClientRegistrationListener;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class Bank {
    private final List<Client> clients = new LinkedList<Client>();
    private List<ClientRegistrationListener> listeners;

    public static class PrintClientListener implements ClientRegistrationListener {
        @Override
        public void onClientAdded(Client client) {
            System.out.println(client.getClientSalutation());
        }
    }

    public static class EmailNotificationListener implements ClientRegistrationListener {
        @Override
        public void onClientAdded(Client client) {
            System.out.println(String.format("Notification email for client %s to be sent", client.getClientSalutation()));
        }
    }

    public static class DebugListener implements ClientRegistrationListener {
        @Override
        public void onClientAdded(Client client) {
            System.out.println(String.format("%s - %s", client.getClientSalutation(), new Date()));
        }
    }

    public Bank(List<ClientRegistrationListener> listeners) {
        this.listeners = listeners;
        listeners.add(new DebugListener());
    }

    public List<Client> getClients() {
        return clients;
    }

    public void addClient(Client client) {
        clients.add(client);
        for (ClientRegistrationListener listener : listeners) {
            listener.onClientAdded(client);
        }
    }
}